// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include <thread>

#include <ktest/ktest.h>

#include <nebula/testing/ktest_util.h>
#include <nebula/future/thread_pool.h>
#include <nebula/trace/tracing_internal.h>

namespace nebula {
namespace util {
namespace tracing {

#ifdef NEBULA_WITH_OPENTELEMETRY

// This test is a regression for ARROW-15604.  OT has some static state that
// can be initialized after the CPU and I/O thread pools.  We need to make
// sure OT's state persists for the lifetime of any threads in those thread
// pools.
//
// This test checks this by spawning a thread task that will outlive the unit
// test's lifetime and so teardown of static state should begin before this
// thread finishes.
TEST(Tracing, OtLifetime) {
  ASSERT_OK(::nebula::internal::get_cpu_thread_pool()->spawn([] {
    // This thread will outlive the main test thread.
    Span span;
    START_SPAN(span, "Test");
    SleepFor(0.1);
  }));
}

#endif

}  // namespace tracing
}  // namespace util
}  // namespace nebula
